package serverlet;

import java.io.IOException;
import java.util.ArrayList;
import java.util.List;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import connectDB.FaqDB;
import connectDB.PacketDB;
import entities.Faqentities;
import entities.Packetentities;

/**
 * Servlet implementation class Faqpaging
 */
@WebServlet("/Faqpaging")
public class Faqpaging extends HttpServlet {
	private static final long serialVersionUID = 1L;
       
    /**
     * @see HttpServlet#HttpServlet()
     */
    public Faqpaging() {
        super();
        // TODO Auto-generated constructor stub
    }

	/**
	 * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {


		int page = 1;
        int records = 15;

        if (request.getParameter("page") != null) {
            page = Integer.parseInt(request.getParameter("page"));
        }
		List<Faqentities> list= new ArrayList<Faqentities>();
        FaqDB faqdb = new FaqDB();

        int start_row = (page * records) - (records - 1);
        int end_row = start_row + records - 1;
        list = faqdb.findvspaging(start_row, end_row);
        //int noOfRecords = ldDB.getTotalRows();
        int numrecords = faqdb.findtotalrows();
        //int noOfPage = ;
        int numofpage = ((int) Math.ceil(numrecords * 1.0 / records));

        request.setAttribute("list", list);
        request.setAttribute("start", start_row);
        request.setAttribute("end", end_row);
        request.setAttribute("noOfPages", numofpage);
        request.setAttribute("currentPage", page);

        RequestDispatcher view = request.getRequestDispatcher("/Manager/faqlist.jsp");
        view.forward(request, response);
		
	}

	/**
	 * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
	 */
	protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
		// TODO Auto-generated method stub
	}

}
